package com.compty.core.framework.plugin;

import org.apache.log4j.Logger;

import com.compty.paint.domain.CustomerInfo;
import com.compty.paint.domain.Order;
import com.compty.paint.domain.PaymentLog;
import com.compty.paint.manager.OrderManager;
import com.compty.paint.service.UserServiceFactory;
import com.compty.paint.service.impl.OrderFlowManager;

public abstract class AbstractPaymentPlugin{
	
	private OrderFlowManager orderFlowManager;
	private OrderManager orderManager; 
	
	protected final Logger logger = Logger.getLogger(getClass());
	
	protected void paySuccess(Integer orderId){
		Order order  = orderManager.get(orderId);
		PaymentLog paymentLog =  new PaymentLog();
		CustomerInfo member  = UserServiceFactory.getUserService().getCurrentMember();
		if( member != null ){
			paymentLog.setPay_user(member.getUserName());
			paymentLog.setMember_name(member.getUserName());
			paymentLog.setCustomerInfo(member);
		}
		
		paymentLog.setPay_type(order.getPayment_type());
		paymentLog.setMoney(order.getOrder_amount());		
		paymentLog.setOrder(order);
		paymentLog.setPay_method(order.getPayment_name());
		this.orderFlowManager.pay(paymentLog);
	}
	
	public void paySuccess(String order_no){
		Order order  = orderManager.findByOrderNo(order_no);
		PaymentLog paymentLog =  new PaymentLog();
		CustomerInfo member  = UserServiceFactory.getUserService().getCurrentMember();
		if( member != null ){
			paymentLog.setPay_user(member.getUserName());
			paymentLog.setMember_name(member.getUserName());
			paymentLog.setCustomerInfo(member);
		}
		
		paymentLog.setPay_type(order.getPayment_type());
		paymentLog.setMoney(order.getOrder_amount());		
		paymentLog.setOrder(order);
		paymentLog.setPay_method(order.getPayment_name());
		this.orderFlowManager.pay(paymentLog);
	}

	public void setOrderManager(OrderManager orderManager) {
		this.orderManager = orderManager;
	}

	public void setOrderFlowManager(OrderFlowManager orderFlowManager) {
		this.orderFlowManager = orderFlowManager;
	}
	
}
